! There are four ways to declare the interface to a subroutine
! (1) using old-fashioned scalar-return-type only declaration
! (2) by containing it inside the routine that calls it
! (3) by containing it in a module
! (4) in an interface block in a module
! (5) can also use something contained in a module using a different name
subroutine part2
   use mystuff
   use myfuns
   implicit none
   real(adequate) manipulate1, manipulate5
   external manipulate1, manipulate5

   write(11, *), "Manipulations"
   write(11, *), manipulate1(x, size(x)), manipulate2(x), manipulate3(x)
   write(11, *), manipulate4(x)
   write(11, *), manipulate5()

   contains

   function manipulate2(x)
       use precision
       real(adequate), intent(in):: x(:)
       integer manipulate2

       manipulate2 = count(x > 0.3_adequate)
   end function manipulate2

end subroutine part2

function manipulate1(x, n) result(w)
! old-style interface, new intrinsic dot_product
   use precision
   real(adequate), intent(in):: x(*)
   real(adequate) w

   w = dot_product(x(1:n), x(1:n))
end function manipulate1

function manipulate4(x) result(p_times_y)
! matrix multiply, etc.
   use precision
   real(adequate), intent(in):: x(:)
   real(adequate) y(size(x)), z(size(x)), p(size(x), size(x))
   real(adequate) p_times_y(size(x))
   integer i, j, n
! array expressions
   y = x**2 + 1.0
   z = x / y
! scalar broadcast
   p = 0.0
! sections
   n = size(x)
   do i = 1, n
      p(i,:) = z * (1.0 / (1.0 + i))
   enddo

   p_times_y = matmul (p, y)

end function manipulate4

function manipulate5() result(s)
! Using and renaming just one function from a module
   use mystuff
   use myfuns, f => manipulate3
   real(adequate) s
   s = f(x)  ! actually calls manipulate3 from myfuns
end function manipulate5




